// import store from '@/store/state'
import cookies from 'js-cookie';
let znk = {
  getLastMonth: format => {
    // 获取上个月日期
    var date = new Date ();
    var year = date.getFullYear ();
    var month = date.getMonth ();
    if (month === 0) {
      year = year - 1;
      month = 12;
    }
    return year + format + month;
  },
  // 时间格式化
  formatDate: (date, fmt) => {
    if (date == null) {
      return '';
    }
    var t = new Date (date);
    var tf = function (i) {
      return (i < 10 ? '0' : '') + i;
    };
    return fmt.replace (/yyyy|MM|dd|HH|mm|ss/g, function (a) {
      switch (a) {
        case 'yyyy':
          return tf (t.getFullYear ());
        case 'MM':
          return tf (t.getMonth () + 1);
        case 'mm':
          return tf (t.getMinutes ());
        case 'dd':
          return tf (t.getDate ());
        case 'HH':
          return tf (t.getHours ());
        case 'ss':
          return tf (t.getSeconds ());
      }
    });
  },
  // 获取自然日-始
  startNatureday: () => {
    var date1 = new Date (
      new Date (new Date ().toLocaleDateString ()).getTime ()
    );
    var startTime =
      date1.getFullYear () +
      '-' +
      (date1.getMonth () + 1 < 10
        ? '0' + (date1.getMonth () + 1)
        : date1.getMonth () + 1) +
      '-' +
      (date1.getDate () < 10 ? '0' + date1.getDate () : date1.getDate ()) +
      ' ' +
      (date1.getHours () < 10 ? '0' + date1.getHours () : date1.getHours ()) +
      ':' +
      (date1.getMinutes () < 10
        ? '0' + date1.getMinutes ()
        : date1.getMinutes ()) +
      ':' +
      (date1.getSeconds () < 10
        ? '0' + date1.getSeconds ()
        : date1.getSeconds ());
    return startTime;
  },
  // 获取自然日-末
  endNatureday: () => {
    var date2 = new Date (
      new Date (new Date ().toLocaleDateString ()).getTime () +
        24 * 60 * 60 * 1000 -
        1
    );
    var endTime =
      date2.getFullYear () +
      '-' +
      (date2.getMonth () + 1) +
      '-' +
      date2.getDate () +
      ' ' +
      date2.getHours () +
      ':' +
      date2.getMinutes () +
      ':' +
      date2.getSeconds ();
    return endTime;
  },
  // 获取当前时间
  /**
     * 用法
     * defaultTime("yyyy-MM-dd");
     * defaultTime("yyyy-MM-dd HH:mm:ss");
     **/
  defaultTime: (date, fmt) => {
    if (date == null) {
      return '';
    }
    var time = new Date (date);
    var o = {
      'M+': time.getMonth () + 1, // 月份
      'd+': time.getDate (), // 日
      'H+': time.getHours (), // 小时
      'm+': time.getMinutes (), // 分
      's+': time.getSeconds (), // 秒
      'q+': Math.floor ((time.getMonth () + 3) / 3), // 季度
      S: time.getMilliseconds (), // 毫秒
    };
    if (/(y+)/.test (fmt))
      fmt = fmt.replace (
        RegExp.$1,
        (time.getFullYear () + '').substr (4 - RegExp.$1.length)
      );
    for (var k in o) {
      if (new RegExp ('(' + k + ')').test (fmt))
        fmt = fmt.replace (
          RegExp.$1,
          RegExp.$1.length === 1
            ? o[k]
            : ('00' + o[k]).substr (('' + o[k]).length)
        );
    }
    return fmt;
  },
  /**
     * 千分位
     */
  fmoney: s => {
    if (!s) s = 0;
    var n = 2;
    n = n > 0 && n <= 20 ? n : 2;
    // eslint-disable-next-line no-useless-escape
    s = parseFloat ((s + '').replace (/[^\d\.-]/g, '')).toFixed (n) + '';
    // eslint-disable-next-line one-var
    var l = s.split ('.')[0].split ('').reverse (), r = s.split ('.')[1];
    var t = '';
    for (var i = 0; i < l.length; i++) {
      t += l[i] + ((i + 1) % 3 === 0 && i + 1 !== l.length ? ',' : '');
    }
    return t.split ('').reverse ().join ('') + '.' + r;
  },
  // 两个浮点数相加
  AddFun: (num1, num2) => {
    var r1, r2, m;
    try {
      r1 = num1.toString ().split ('.')[1].length;
    } catch (e) {
      r1 = 0;
    }
    try {
      r2 = num2.toString ().split ('.')[1].length;
    } catch (e) {
      r2 = 0;
    }
    m = Math.pow (10, Math.max (r1, r2));
    // return (num1*m+num2*m)/m;
    return Math.round (num1 * m + num2 * m) / m;
  },
  // 两个浮点数相减
  SubFun: (num1, num2) => {
    var r1, r2, m, n;
    try {
      r1 = num1.toString ().split ('.')[1].length;
    } catch (e) {
      r1 = 0;
    }
    try {
      r2 = num2.toString ().split ('.')[1].length;
    } catch (e) {
      r2 = 0;
    }
    m = Math.pow (10, Math.max (r1, r2));
    n = r1 >= r2 ? r1 : r2;
    return (Math.round (num1 * m - num2 * m) / m).toFixed (n);
  },
  // 两数相除
  DivFun: (num1, num2) => {
    var t1, t2, r1, r2;
    try {
      t1 = num1.toString ().split ('.')[1].length;
    } catch (e) {
      t1 = 0;
    }
    try {
      t2 = num2.toString ().split ('.')[1].length;
    } catch (e) {
      t2 = 0;
    }
    r1 = Number (num1.toString ().replace ('.', ''));
    r2 = Number (num2.toString ().replace ('.', ''));
    return r1 / r2 * Math.pow (10, t2 - t1);
  },

  MulFun: (num1, num2) => {
    // eslint-disable-next-line one-var
    var m = 0, s1 = num1.toString (), s2 = num2.toString ();
    try {
      m += s1.split ('.')[1].length;
    } catch (e) {}
    try {
      m += s2.split ('.')[1].length;
    } catch (e) {}
    return (
      Number (s1.replace ('.', '')) *
      Number (s2.replace ('.', '')) /
      Math.pow (10, m)
    );
  },
  /** 公用的新增修改回调函数
     * that：this
     * fun 接口
     * params 传参
     * restForms 需要重置的表单
     * susCallbck 成功后回调
     * errCallback错误回调
     */
  AddUpdate: (that, fun, params, restForms, susCallbck, errCallback) => {
    fun (params).then (res => {
      if (res.code === 0) {
        that.$message ({
          message: that.DialogTit + '成功！',
          type: 'success',
          duration: 500,
        });
        // eslint-disable-next-line no-unused-expressions
        susCallbck ? susCallbck (that) : '';
        that.$refs[restForms].resetFields ();
        // Object.assign(that.$data, that.$options.data()); //初始化数据
        // that.listpager({ rows: that.pageSize });
      } else {
        that.$message.error ({
          message: res.message || that.DialogTit + '失败！',
          duration: 1000,
        });
        // eslint-disable-next-line no-unused-expressions
        errCallback ? errCallback () : '';
      }
    });
  },
  /** *json数组中通过value值获取索引值
     * arr：json数组 var a=[{a:1},{c:1}]
     * json数组检索对象的key值  key=c
     * value检索对象属性值 如 var value=1
     * */
  valueIndex: (arr, key, value) => {
    for (let n in arr) {
      if (arr[n][key] === value) {
        return n;
      }
    }
  },
  removeClass: (btnAll, hasClass, activeClass) => {
    for (let i = 0; i < btnAll.length; i++) {
      if (btnAll[i].classList.value.indexOf (hasClass) >= 0) {
        btnAll[i].classList.remove (activeClass);
      }
    }
  },
  addClass: (el, addClass) => {
    el.$el.className += ' ' + addClass;
  },
  /**
     * 选中效果且不删除兄弟元素
     *  el :点击对象元素
     * ctiveClass：选中对象Class
     */
  selfActive: (el, activeClass) => {
    let index = el.$el.className.indexOf (activeClass);
    if (index >= 0) {
      el.$el.className = el.$el.className.substring (0, index);
    } else {
      znk.addClass (el, activeClass);
    }
  },
  /** * 选中效果且删除兄弟元素
     * el :点击对象元素
     * activeEl： 所有点击对象元素
     * activeClass：选中对象Class
     * hasClass : 用于筛选自己需要删除的元素
     * 添加回调
     * 删除回调
     */
  active: (
    el,
    activeEl,
    activeClass,
    hasClass,
    addCallback,
    removeCallback
  ) => {
    let btnAll = el.$el.parentNode.getElementsByTagName (activeEl);
    let index = el.$el.className.indexOf (activeClass);
    if (index >= 0) {
      el.$el.className = el.$el.className.substring (0, index);
      // eslint-disable-next-line no-unused-expressions
      removeCallback ? removeCallback (el, btnAll) : '';
    } else {
      znk.removeClass (btnAll, hasClass, activeClass);
      znk.addClass (el, activeClass);
      if (addCallback) {
        addCallback (el, btnAll);
      }
    }
  },
  /**
     * 数组去空
     * arr: 数组
     *  */
  removeEmptyArrayEle: arr => {
    for (var i = 0; i < arr.length; i++) {
      if (arr[i] === undefined || arr[i].length === 0) {
        arr.splice (i, 1);
        i = i - 1; // i - 1 ,因为空元素在数组下标 2 位置，删除空之后，后面的元素位置，删除空之后，后面的元素要向前补位，
        // 这样才能真正去掉空元素,觉得这句可以删掉的连续为空试试，然后思考其中逻辑
      }
    }
    return arr;
  },
  /***
     * json 转换为字符串拼接方式
     */
  jsonStr: arr => {
    let txt = '';
    for (let item in arr) {
      if (item && arr[item]) {
        txt += item + '=' + arr[item] + '&';
      }
    }
    txt = txt.substr (0, txt.length - 1);
    return txt;
  },
  /**
     * 获取select 选中的label值
     * @param {*} arrs  select 列表数组
     * @param {*} selectVal   select 选中的值
     * @param {*} value select 选中的value值绑定 字段
     * @param {*} label select 选中的label值绑定 字段
     */
  selectLabel (arrs, selectVal, value, label) {
    let arr = [];
    arr = arrs;
    let obj = {};
    obj = arr.find (item => {
      return item[value] === selectVal; // 比如：选项2
    });
    if (obj !== '' && obj !== undefined) {
      return obj[label]; // 获取label的值 0-2000
    }
  },
  /**
     * 为数组添加指定空数据长度
     * @param {*} arr 数组
     * @param {*} length 长度
     */
  addEmptyData (arr, length) {
    // console.log(arr)
    // 20190114 修改i<length   为i<6
    for (let i = 0; i < 6; i++) {
      for (let j = arr[i].length; arr[i].length < length; j++) {
        arr[i][j] = '';
      }
    }
    // 返回显示数组
    // console.log(arr)
    return arr;
  },
  /**
     * 手动计算合计
     * @param {*} arr 数组
     * @param {*} labelArr 需要计算合计字段对象数组
     */
  handSum (arr, labelArr) {
    let rt = {};
    for (let i = 0; i < labelArr.length; i++) {
      rt[labelArr[i]] = '';
      for (let j = 0; j < arr.length; j++) {
        if (arr[j].hasOwnProperty (labelArr[i])) {
          rt[labelArr[i]] = znk.AddFun (
            rt[labelArr[i]],
            arr[j][labelArr[i]] || 0
          );
        } else {
          console.warn (labelArr[i] + '字段不存在！');
        }
      }
    }
    return rt;
  },
  /**
     *删除对象中特定字段
     * @param {*} param 对象
     * @param {*} arr 字段数组
     */
  deleteLabel (param, arr) {
    for (let item in arr) {
      if (param) {
        delete param[arr[item]];
      } else {
        console.warn ('deleteLabel函数参数parma对象不存在');
      }
    }
    return param;
  },
  /**
     *获取cookie
     * @param {*} name
     * @returns
     */
  getCookie (name, strCookie) {
    // console.log('strCookie',strCookie)

    // var arrCookie = strCookie.split(';')

    // for (var i = 0; i < arrCookie.length; i++) {

    //   var arr = arrCookie[i].split('=')

    //   if (arr[0].trim() === name) {

    //     return arr[1]

    //   }
    // }
    // return {}
    var arr = null;
    var reg = new RegExp ('(^| )' + name + '=([^;]*)(;|$)');
    // eslint-disable-next-line no-cond-assign
    if (process.client) {
      if ((arr = document.cookie.match (reg))) {
        return arr[2];
      } else {
        return null;
      }
    }
  },
  /**
     *设置cookie,增加到vue实例方便全局调用
     * @param {*} cname
     * @param {*} value
     * @param {*} expiredays 过期时间
     */
  setCookie (cname, value, expiredays) {
    var exdate = new Date ();
    exdate.setDate (exdate.getDate () + expiredays);
    document.cookie =
      cname +
      '=' +
      escape (value) +
      (expiredays == null ? '' : ';expires=' + exdate.toGMTString ());
  },
  /**
     *删除cookie
     * @param {*} name
     */
  delCookie (name) {
    var exp = new Date ();
    exp.setTime (exp.getTime () - 1);
    var cval = znk.getCookie (name);
    if (cval != null) {
      document.cookie = name + '=' + cval + ';expires=' + exp.toGMTString ();
    }
  },
  /**
     *金额大写转换
     */
  DX (n) {
    n = n * 10000;
    if (!/^(0|[1-9]\d*)(\.\d+)?$/.test (n)) {
      return '数据非法';
    }
    var unit = '千百拾亿千百拾万千百拾元角分';
    var str = '';
    n += '00';
    var p = n.indexOf ('.');
    if (p >= 0) {
      n = n.substring (0, p) + n.substr (p + 1, 2);
    }
    unit = unit.substr (unit.length - n.length);
    for (var i = 0; i < n.length; i++) {
      str += '零壹贰叁肆伍陆柒捌玖'.charAt (n.charAt (i)) + unit.charAt (i);
    }
    return str
      .replace (/零(千|百|拾|角)/g, '零')
      .replace (/(零)+/g, '零')
      .replace (/零(万|亿|元)/g, '$1')
      .replace (/(亿)万|壹(拾)/g, '$1$2')
      .replace (/^元零?|零分/g, '')
      .replace (/元$/g, '元整');
  },
  /**
     *数字转换金额格式化
     *设置type 不带小数位(默认是有小数位)
     */
  formatMoney (s, type) {
    s = s * 10000;
    // eslint-disable-next-line no-useless-escape
    if (/[^0-9\.]/.test (s)) {
      return '0';
    }
    if (s == null || s === '') {
      return '0';
    }
    s = s.toString ().replace (/^(\d*)$/, '$1.');
    s = (s + '00').replace (/(\d*\.\d\d)\d*/, '$1');
    s = s.replace ('.', ',');
    var re = /(\d)(\d{3},)/;
    while (re.test (s)) {
      s = s.replace (re, '$1,$2');
    }
    s = s.replace (/,(\d\d)$/, '.$1');
    if (type === 0) {
      var a = s.split ('.');
      if (a[1] === '00') {
        s = a[0];
      }
    }
    return s + ' 元';
  },
  /*
     *打印时间拆分
     */
  splitTime (time) {
    // eslint-disable-next-line no-useless-escape
    var timearr = time.replace (' ', ':').replace (/\:/g, '-').split ('-');
    return timearr;
  },
  Throttle (fn, t) {
    let last;
    let timer;
    let interval = t || 500;
    return function () {
      let args = arguments;
      let now = +new Date ();
      if (last && now - last < interval) {
        clearTimeout (timer);
        timer = setTimeout (() => {
          last = now;
          fn.apply (this, args);
        }, interval);
      } else {
        last = now;
        fn.apply (this, args);
      }
    };
  },
  isEmpty (val) {
    if (val.length > 0) {
      return false;
    } else {
      return true;
    }
  },
  /**
     * 日期解析，字符串转日期
     * @param dateString 可以为2017-02-16，2017/02/16，2017.02.16
     * @returns {Date} 返回对应的日期对象
     */
  dateParse (dateString) {
    var SEPARATOR_BAR = '-';
    var SEPARATOR_SLASH = '/';
    var SEPARATOR_DOT = '.';
    var dateArray;
    if (dateString.indexOf (SEPARATOR_BAR) > -1) {
      dateArray = dateString.split (SEPARATOR_BAR);
    } else if (dateString.indexOf (SEPARATOR_SLASH) > -1) {
      dateArray = dateString.split (SEPARATOR_SLASH);
    } else {
      dateArray = dateString.split (SEPARATOR_DOT);
    }
    return new Date (dateArray[0], dateArray[1] - 1, dateArray[2]);
  },

  /**
     * 日期比较大小
     * compareDateString大于dateString，返回1；
     * 等于返回0；
     * compareDateString小于dateString，返回-1
     * @param dateString 日期
     * @param compareDateString 比较的日期
     */
  dateCompare (dateString, compareDateString) {
    if (znk.isEmpty (dateString)) {
      console.warn ('dateString不能为空');
      return;
    }
    if (znk.isEmpty (compareDateString)) {
      console.warn ('compareDateString不能为空');
      return;
    }
    var dateTime = znk.dateParse (dateString).getTime ();
    var compareDateTime = znk.dateParse (compareDateString).getTime ();
    if (compareDateTime > dateTime) {
      return 1;
    } else if (compareDateTime === dateTime) {
      return 0;
    } else {
      return -1;
    }
  },

  /**
     * 判断日期是否在区间内，在区间内返回true，否返回false
     * @param dateString 日期字符串
     * @param startDateString 区间开始日期字符串
     * @param endDateString 区间结束日期字符串
     * @returns {Number}
     */
  isDateBetween (dateString, startDateString, endDateString) {
    if (znk.isEmpty (dateString)) {
      console.warn ('dateString不能为空');
      return;
    }
    if (znk.isEmpty (startDateString)) {
      console.warn ('startDateString不能为空');
      return;
    }
    if (znk.isEmpty (endDateString)) {
      console.warn ('endDateString不能为空');
      return;
    }
    var flag = false;
    var startFlag = znk.dateCompare (dateString, startDateString) < 1;
    var endFlag = znk.dateCompare (dateString, endDateString) > -1;
    if (startFlag && endFlag) {
      flag = true;
    }
    return flag;
  },

  /**
     * 判断日期区间[startDateCompareString,endDateCompareString]是否完全在别的日期区间内[startDateString,endDateString]
     * 即[startDateString,endDateString]区间是否完全包含了[startDateCompareString,endDateCompareString]区间
     * 在区间内返回true，否返回false
     * @param startDateString 新选择的开始日期，如输入框的开始日期
     * @param endDateString 新选择的结束日期，如输入框的结束日期
     * @param startDateCompareString 比较的开始日期
     * @param endDateCompareString 比较的结束日期
     * @returns {Boolean}
     */
  isDatesBetween (
    startDateString,
    endDateString,
    startDateCompareString,
    endDateCompareString
  ) {
    if (znk.isEmpty (startDateString)) {
      console.warn ('startDateString不能为空');
      return;
    }
    if (znk.isEmpty (endDateString)) {
      console.warn ('endDateString不能为空');
      return;
    }
    if (znk.isEmpty (startDateCompareString)) {
      console.warn ('startDateCompareString不能为空');
      return;
    }
    if (znk.isEmpty (endDateCompareString)) {
      console.warn ('endDateCompareString不能为空');
      return;
    }
    var flag = false;
    var startFlag =
      znk.dateCompare (startDateCompareString, startDateString) < 1;
    var endFlag = znk.dateCompare (endDateCompareString, endDateString) > -1;
    if (startFlag && endFlag) {
      flag = true;
    }
    return flag;
  },
  resetForm (that, formName) {
    if (formName && that.$refs[formName]) {
      that.$refs[formName].resetFields ();
    }
  },
  // 固话验证
  telephone (rules, value, callback) {
    let el = !/^(\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,14}$/.test (value);
    if (value === '') {
      callback (new Error ('电话号码不能为空！'));
    } else if (!el) {
      callback (new Error ('电话号码格式不正确！'));
    } else {
      callback ();
    }
  },
  // 中文
  isChinese (value) {
    return /[\u4e00-\u9fa5]/.test (value);
  },
  // 中文姓名
  isChineseUser (value) {
    return /[^\u4E00-\u9FA5]/g.test (value);
  },
  // 全数字
  isNum (value) {
    return /^[0-9]\d*$/.test (value);
  },
  // 全英文
  isEng (value) {
    return /^[a-zA-Z]*$/.test (value);
  },
  // 身份证
  isIdCard (value) {
    return /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test (
      value.toUpperCase ()
    );
  },
  // 英文、数字、汉字
  isUserName (value) {
    return /^[a-zA-Z0-9\u4E00-\u9FA5]+$/.test (value);
  },
  // 英文、数字
  isPwd (rules, value, callback) {
    console.log ('rules', rules);
    var el = /^[0-9a-zA-Z]+$/.test (value);
    if (value === '') {
      callback (new Error (rules.msg));
    } else if (!el) {
      callback (new Error ('只能输入数字或者字母'));
    } else {
      callback ();
    }
  },
  // 8-18 数字加字母
  isPwd02 (value) {
    return /^(?![a-z]+$)(?!\d+$)[a-z0-9]{8,18}$/i.test (value);
  },
  // 字符串转日期格式，strDate要转为日期格式的字符串
  getLocalTime (nS) {
    return new Date (parseInt (nS) * 1000).toLocaleString ().substr (0, 17);
  },
  // alert(getLocalTime(1293072805));
  // 整数，小数
  isNumPoint (value) {
    return /^[0-9]+([.]{1}[0-9]+){0,1}$/.test (value);
  },
  // 身份证
  isIdCards (idCard) {
    // 15位和18位身份证号码的正则表达式
    var regIdCard = /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/;
    // 如果通过该验证，说明身份证格式正确，但准确性还需计算
    if (regIdCard.test (idCard)) {
      if (idCard.length === 18) {
        // eslint-disable-next-line no-array-constructor
        var idCardWi = new Array (
          7,
          9,
          10,
          5,
          8,
          4,
          2,
          1,
          6,
          3,
          7,
          9,
          10,
          5,
          8,
          4,
          2
        ); // 将前17位加权因子保存在数组里
        // eslint-disable-next-line no-array-constructor
        var idCardY = new Array (1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2); // 这是除以11后，可能产生的11位余数、验证码，也保存成数组
        var idCardWiSum = 0; // 用来保存前17位各自乖以加权因子后的总和
        for (var i = 0; i < 17; i++) {
          idCardWiSum += idCard.substring (i, i + 1) * idCardWi[i];
        }
        var idCardMod = idCardWiSum % 11; // 计算出校验码所在数组的位置
        var idCardLast = idCard.substring (17); // 得到最后一位身份证号码
        // 如果等于2，则说明校验码是10，身份证号码最后一位应该是X
        if (idCardMod === 2) {
          if (idCardLast === 'X' || idCardLast === 'x') {
            return true;
          } else {
            return false;
          }
        } else {
          // 用计算出的验证码与最后一位身份证号码匹配，如果一致，说明通过，否则是无效的身份证号码
          if (idCardLast === idCardY[idCardMod]) {
            return true;
          } else {
            return false;
          }
        }
      }
    } else {
      return false;
    }
    return true;
  },
  /**
     * 邮件
     */
  isEmail (rules, value, callback) {
    // eslint-disable-next-line no-useless-escape
    var el = /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test (
      value
    );
    if (value === '') {
      callback (new Error ('请输入邮箱！'));
    } else if (!el) {
      callback (new Error ('邮箱格式不正确！'));
    } else {
      callback ();
    }
  },
  /**
     * 数字验证
     * wlf
     */
  isNumber (rules, value, callback) {
    // eslint-disable-next-line no-useless-escape
    var el = /^[0-9]+([.]{1}[0-9]+){0,1}$/.test (value);
    if (value === '') {
      callback (new Error ('不能为空'));
    } else if (!el) {
      callback (new Error ('只能输入数字'));
    } else {
      callback ();
    }
  },
  /**
     * 数字验证
     * wlf
     */
  isPhone (rules, value, callback) {
    // eslint-disable-next-line no-useless-escape
    var el = /^[0-9]*$/.test (value);
    if (value === '') {
      callback (new Error ('请输入手机号码'));
    } else if (!el) {
      callback (new Error ('请输入正确的手机号码'));
    } else {
      callback ();
    }
  },
  /**
     * 密码设置确认
     * wlf
     */
  // password (rule, value, callback) {
  //   let that = store.state.that
  //   if (value === '' || !value) {
  //     callback(new Error('请输入密码'))
  //   } else if (value.length < 6) {
  //     callback(new Error('密码长度大于6位'))
  //   } else {
  //     if (that.addForm.checkpwd !== '') {
  //       that.$refs.addForm.validateField('checkPass')
  //     }
  //     callback()
  //   }
  // },
  // checkpwd (rule, value, callback) {
  //   let that = store.state.that
  //   if (value === '') {
  //     callback(new Error('请再次输入密码'))
  //   } else if (value !== that.addForm.password) {
  //     callback(new Error('两次输入密码不一致!'))
  //   } else {
  //     callback()
  //   }
  // },
  /**
     * 根据数据字典获取指定code数据
     * @param data 数据字典
     * @param codeName 数据字典标时
     * @returns {json}
     */
  dict (data, codeName) {
    let dict = [];
    let dictJson = {};
    for (var i = 0; i < data.length; i++) {
      if (data[i].typeCode === codeName && typeof codeName === 'string') {
        dict.push (data[i]);
      } else if (typeof codeName === 'object') {
        for (var j = 0; j < codeName.length; j++) {
          if (data[i].typeCode === codeName[j]) {
            if (typeof dictJson[codeName[j]] !== 'object') {
              dictJson[codeName[j]] = [];
            }
            dictJson[codeName[j]].push (data[i]);
          }
        }
      }
    }
    return typeof codeName === 'string' ? dict : dictJson;
  },
  // isCountry: function (rules, value, callback) {
  //   let that = store.state.that
  //   if (!that.$store.state.pro) {
  //     callback(new Error('请选择省！'))
  //   } else if (!that.$store.state.city) {
  //     callback(new Error('请选择市！'))
  //   } else if (!that.$store.state.country && that.$store.state.pro !== '台湾省') {
  //     callback(new Error('请选择区！'))
  //   } else {
  //     callback()
  //   }
  // }
};
export {znk};
